package net.iiyasvn.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.iiyasvn.R;
import net.iiyasvn.model.FansInfo;
import net.iiyasvn.model.FansInfoList;
import net.iiyasvn.task.AsyncImageLoader;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FansAdapter extends BaseAdapter{
	private List<FansInfo> info = null;
	private Map<Integer,View> rowViews = new HashMap<Integer,View>();
	private Context context = null;
	private AsyncImageLoader asyncImageLoader = AsyncImageLoader.getInstance();
	public FansAdapter(FansInfoList fansInfoList, Context context){
		info = fansInfoList.getInfo();
		this.context = context;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return info.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return info.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = rowViews.get(position);
		if(rowView == null){
			LayoutInflater layoutInflater = LayoutInflater.from(context);
			rowView = layoutInflater.inflate(R.layout.fans_list_item, null);
			TextView nickname = (TextView)rowView.findViewById(R.id.nickname);
			ImageView userface = (ImageView)rowView.findViewById(R.id.userface);
			TextView introduce = (TextView)rowView.findViewById(R.id.introduce);
			LinearLayout bnEdit = (LinearLayout)rowView.findViewById(R.id.bnEdit);
			final FansInfo fansInfo = (FansInfo)getItem(position);
			if(fansInfo != null){
				nickname.setText(fansInfo.getNickname());
				introduce.setText(fansInfo.getIntroduce());
				System.out.println(fansInfo.getUserface());
				asyncImageLoader.loadPortrait(fansInfo.getuId(), fansInfo.getUserface(), userface);
				if("0".equals(fansInfo.getIsfollowed())){
					bnEdit.setVisibility(View.GONE);
				}else{
					bnEdit.setVisibility(View.VISIBLE);
				}
	        }
				
			rowViews.put(position, rowView);
			}
		return rowView;
	}
}
